package com.zhtools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class LoggerUtils {
    private static String PATTERN = "\\{\\}";
    private static String FIND_PATTERN = "(\\{\\})";

    public static String getLoggerMsg(String v1, Object... v2) {
        Pattern pattern = Pattern.compile(FIND_PATTERN);
        Matcher matcher = pattern.matcher(v1);
        int count = 0;
        while (matcher.find()) {
            count = count + 1;
        }
        if (count == 0) {
            return v1;
        }

        int length = count;
        if (v2.length < count) {
            length = v2.length;
        }
        for (int i = 0; i < length; i++) {
            Object o = v2[i];
            v1 = v1.replaceFirst(PATTERN, o.toString());
        }
        return v1;
    }
}
